package com.ruoyi.web.core.config;

import com.getui.push.v2.sdk.ApiHelper;
import com.getui.push.v2.sdk.GtApiConfiguration;
import com.getui.push.v2.sdk.api.PushApi;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * 个推应用信息
 *
 * @author ZQB
 * @date 2022/9/20 16:50
 */

@Data
@Component
@ConfigurationProperties(prefix = "getui.app")
public class GeTuiConfig {

    private String appId;

    private String appKey;

    private String appSecret;

    private String masterSecret;

    private String host;

    /**
     * 个推接口实例化
     * @return
     */
    @Bean(name = "onlyPushApi")
    public PushApi pushApi() {
        GtApiConfiguration apiConfiguration = new GtApiConfiguration();
        //填写应用配置，参数在“Uni Push”下的“应用配置”页面中获取
        apiConfiguration.setAppId(appId);
        apiConfiguration.setAppKey(appKey);
        apiConfiguration.setMasterSecret(masterSecret);
//        apiConfiguration.setDomain("https://restapi.getui.com/v2/");
        //实例化ApiHelper对象，用于创建接口对象
        ApiHelper apiHelper = ApiHelper.build(apiConfiguration);
        //创建对象，建议复用。目前有PushApi、StatisticApi、UserApi
        PushApi pushApi = apiHelper.creatApi(PushApi.class);
        return pushApi;
    }

}